package com.mercury.tests;
import java.util.List;

import org.hibernate.*;
import com.mercury.beans.*;

public class Test1 {
	@SuppressWarnings("unchecked")
	public static void main(String[] args){
		Session session = HibernateUtil.currentSession();  //different session
		//save a record******************************
		Transaction tx = session.beginTransaction();
		User user = new User("Tom",45);
		session.save(user);
		tx.commit();
		//retrieve all records**********************
		//session.evict(user);  //Detached
		String hql = "from User";
		Query query = session.createQuery(hql);
		List<User> users = query.list();  //already return list of user bean
		for(User u:users){
			System.out.println(u);
		}
		HibernateUtil.closeSession();
	}
}
